const mongoose = require("./db");
const { getId } = require("../utils/getMethods");
// 购物车页面的数据

// 商品列表
const cartInfoListSchema = new mongoose.Schema({
  skuId: {
    // 商品id
    type: Number,
    required: true,
    unique: true,
    default: () => getId,
  },
  skuType: {
    type: Number, // 商品类型    2
  },
  isNewPerson: {
    type: Number, // 是否新人   1
  },
  skuName: {
    type: String, // 商品名称
  },
  cartPrice: {
    type: Number, // 价格
  },
  skuNum: {
    type: Number, // 数量
  },
  perLimit: {
    type: Number, // 限购数量
  },
  imgUrl: {
    type: String, // 图片地址
  },
  isChecked: {
    type: Number, // 是否选中
  },
  activityRule: Number, // 活动规则
});

// 优惠券列表
const couponInfoListSchema = new mongoose.Schema({
  id: {
    // 优惠券id
    type: Number,
    required: true,
    unique: true,
    default: () => getId,
  },
  couponType: {
    // 优惠券类型
    type: String, //新品，便利，
    required: true,
  },
  amount: {
    // 优惠券金额
    type: Number,
    required: true,
  },
  startTime: {
    // 优惠券开始时间
    type: String, // '2020-05-01 00:00:00'
    required: true,
  },
  endTime: {
    // 优惠券结束时间
    type: String, // '2020-05-01 00:00:00'
    required: true,
  },
  rangeType: {
    // 优惠券范围类型
    type: String, // 全部商品
    required: true,
  },
  rangeDesc: {
    // 优惠券范围描述
    type: String, // 购买任意商品即可使用
    required: true,
  },
  perLimit: {
    // 每人限领数量
    type: String, //  99
    required: true,
  },
  expireTime: {
    // 优惠券过期时间
    type: String, // '2020-05-01 00:00:00'
    required: true,
  },
  couponStatus: {
    // 优惠券状态
    type: Number, // 1
    required: true,
  },
  isSelect: {
    // 是否选中
    type: Number, // 1
    required: true,
  },
  isOptimal: {
    // 是否最优
    type: String, // 1
    required: true,
  },
});

// 活动规则列表
const activityRuleSchema = new mongoose.Schema({
  id: {
    type: Number,
    required: true,
    unique: true,
    default: () => getId,
  },
  ruleDesc: {
    type: String, // 活动规则描述
    required: true, // '满100减10'
  }, // '满99减4'
});

// 活动列表
const activityCartListSchema = new mongoose.Schema({
  activityReduceAmount: {
    // 活动减金额
    type: Number, // 0
    required: true,
  },
  couponReduceAmount: {
    // 优惠券减金额
    type: Number, // 0
    required: true,
  },
  originalTotalAmount: {
    // 原始总金额
    type: Number, // 126
    required: true,
  },
  totalAmount: {
    // 总金额
    type: Number, // 97
    required: true,
  },
});

// 商品列表
const cartInfoListModel = mongoose.model(
  "cartInfoList",
  cartInfoListSchema,
  "cartInfoList"
);

// 优惠券列表
const couponInfoListModel = mongoose.model(
  "couponInfoList",
  couponInfoListSchema,
  "couponInfoList"
);

// 活动规则列表
const activityRuleModel = mongoose.model(
  "activityRule",
  activityRuleSchema,
  "activityRule"
);

// 活动列表
const activityCartListModel = mongoose.model(
  "activityCartList",
  activityCartListSchema,
  "activityCartList"
);

module.exports = {
  cartInfoListModel,
  couponInfoListModel,
  activityRuleModel,
  activityCartListModel,
};
